package com.yupi.oj.model.enums;

import lombok.*;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 语言类型的枚举类
 */
@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum LanguageTypeEnum {
    JAVA("1","JAVA"),
    CPLUSPLUS("2","C++"),
    C("3","C"),
    PYTHON("4","PYTHON");

    private String languageId;
    private String language;

    /**
     * 获取枚举类中的value列表
     * @return
     */
    public static List<String> getValues(){
        return Arrays.stream(values()).map(item -> item.language).collect(Collectors.toList());
    }

    /**
     * 根据 key获取到对应枚举
     *
     * @param languageId
     * @return
     */
    public static LanguageTypeEnum getEnumByValue(String languageId) {
        if (ObjectUtils.isEmpty(languageId)) {
            return null;
        }
        for (LanguageTypeEnum languageTypeEnum : LanguageTypeEnum.values()) {
            if(languageTypeEnum.languageId.equals(languageId))
                return languageTypeEnum;
        }
        return null;
    }
}
